package com.imooc.scala

object HelloWorld {

  def main(args: Array[String]): Unit = {

//    println(add(2,3))
//    println(three)
//    sayHello
//
//    sayName()
//    sayName("墨子")
//
//    loadConf()
//
//    println(speed(100,10))
//    println(speed(distance = 100,time = 10))
//    println(speed(time = 10,distance = 100))
//
//    println(sum(1,2))
//    println(sum(1,2,3))
//    println(sum(1,2,3,4))

//    for(i <- 1 to 10 if i % 2 == 0){
//      println(i)
//    }
//
//    val coures = Array("Hadoop","Spark SQL","Spark Streaming","Storm","Scala")
//    coures.foreach(course => println(course))
//
//    var (num,sum) = (100,0)
//    while(num > 0) {
//      sum = sum + num
//      num = num - 1
//    }
//    println(sum)

  }

  def add(x:Int,y:Int):Int = {
    x + y
  }

  def three() = 1+2

  def sayHello(): Unit ={
    println("Say hello ....")
  }

  // 函数参数可以有默认值
  def sayName(name: String = "PK"): Unit ={
    println(name)
  }

  def loadConf(conf: String = "spark-defaults.conf"): Unit ={
    println(conf)
  }

  // scala 的可变参数
  def speed(distance:Float,time:Float):Float = {
    distance/time
  }

  // 可变参数
  def sum(numbers: Int*): Int = {
    var result = 0

    for (number <- numbers){
      result += number
    }

    result
  }



}
